#!/bin/sh 
#------------------------ LANDP Linux Setup Utility  ------------------------+
#                                                                            |
#  Description : This utility performs the functions required to prepare a   |
#                Linux workstation for running LANDP.                        | 
#                                                                            |
#  Contents    : ehcsetup                                                    |
#                                                                            |
#  Release     : 6.00                                                        |
#                      Start date       Current date                         |
#  Level       : 0.0   10/09/01                                              |
#                1.0   18/03/03    HD05015                                   | 
#                2.0   21/03/03    HD05042                                   | 
#                3.0   06/06/03    HD07832                                   |
#                                                                            |
#  Copyright   : IBM Licensed Materials                                      |
#                                                                            |
#                All Rights Reserved  - Property of IBM                      |
#                                                                            |
#                5724-B16 (C) Copyright IBM Corp. 2000, 2002                 |
#                                                                            |
#                                                                            |
#  Programmer  : Jay Stidder                                                 |
#                                                                            |
#  Maintained  : Jay Stidder                                                 |
#                                                                            |
#  Change activity:                                                          |
#                                                                            |
#  Flag Reason  Rlse  Date  Origin  Description                              |
#  ---- ------  ---- ------ ------  -----------------------------------------|
#  $A0= 004476  0600 030318 hdjns   SHFILE Directory Creation                |
#  $A1= 004575  0600 030321 hdjns   Amend copyright statement                |
#  $A2= 004673  0600 030606 hdjns   Remove CR,Ctrl-Z from autofbss           |
#                                                                            |
#----------------------------------------------------------------------------+

#--------------------------------------------------
# print_copyright - Print LANDP Copyright Statement
#--------------------------------------------------
print_copyright ()
{
 landp_display
 landp_display "IBM (TM) LAN Distributed Platform Version 6.0 - LANDP"
 landp_display "5724-B16 (C) Copyright IBM Corp. 2000, 2002"
 landp_display "Licensed Materials - Property of IBM - All Rights reserved."
 landp_display "(TM) Trademark of International Business Machines Corporation"
 landp_display "LANDP is a trademark of International Business Machines Corporation"
 landp_display
}

#---------------------------------------------
# get_parameters - Get Command Line Parameters
#---------------------------------------------
get_parameters ()
{
 landp_display
 landp_logging "`$messages 10010 \"$m10010\"`" 
 private_landp_logging "$*"

 [ "`basename $0`" = "ehcremove" ] && remove_landp
     
 while [ -n "$1" ]
    do
       case $1 in
          -rl)  shift;  release=$1 ;;
          -wd)  shift;  landp_wsid=$1 ;;
          -rm)  shift;  remove_landp ;;
          -wx)  shift;  waction=$1 ;;
          -rx)  shift;  laction=$1 ;;
          -cu)  shift;  create_landp_group ; create_landp_users ; exit 0 ;;
          -cm)  shift;  create_landp_group ; create_manager_account ; exit 0 ;;
          -cg)  shift;  create_landp_group ; exit 0 ;;
          -ap)  pass_file="Y" ;;
          -dd)  shift;  landp_tdir=$1 ;;
          -wp)  shift;  wpath=$1 ;;
          -nu)  no_user="Y" ;;
          -dm)  default_manager="Y" ;;
          -dg)  default_group="Y" ;;
          -pr)  shift;  prompt_type=$1 ;;
          -qt)  quiet="Y" ;;
          -ip)  no_parm_file="Y" ;;
          -cp)  check_parameters="Y" ;;
 
          --landp_release)           shift;  release=$1 ;;
          --workstation_directory)   shift;  landp_wsid=$1 ;;
          --remove)                  shift;  remove_landp ;;
          --ws_dir_exist)            shift;  waction=$1 ;;
          --release_exist)           shift;  laction=$1 ;;
          --create_user)             shift
                                     create_landp_group
                                     create_landp_users ; exit 0 ;;
          --create_manager)          shift
                                     create_landp_group
                                     create_manager_account ; exit 0 ;;
          --create_group)            shift;  create_landp_group ; exit 0 ;;
          --add_password)            pass_file="Y" ;;
          --distribution_directory)  shift;  landp_tdir=$1 ;;
          --workstation_path)        shift;  wpath=$1 ;;
          --no_user)                 no_user="Y" ;;
          --default_manager)         default_manager="Y" ;;
          --default_group)           default_group="Y" ;;
          --prompt)                  shift;  prompt_type=$1 ;;  
          --quiet)                   quiet="Y" ;;
          --ignore_parameter_file)   no_parm_file="Y" ;;
          --check_parameters)        check_parameters="Y" ;;

           *)  print_usage ; exit_setup ;;    
       esac
       shift
    done
}

#----------------------------------
# print_usage - Print Usage Summary
#----------------------------------
print_usage ()
{
 print_copyright

 ver="ID=EHCSETUP VL=L6003 HD07832 "
 verdate="June 2003"

 echo
 echo "`basename $0` : LANDP for Linux" $ver $verdate
 echo
 echo "      ehcsetup [--landp_release REL]               *"
 echo "               [--workstation_directory WSID]      *"
 echo "               [--distribution_directory DIR]      *"
 echo "               [--workstation_path WDPATH]         *"
 echo "               [--no_user]                         *"
 echo "               [--default_manager]                 *"
 echo "               [--default_group]                   *"
 echo
 echo "               [--ws_dir_exist cancel|clear|replace]"
 echo "               [--release_exist cancel|clear|replace]"
 echo "               [--add_password]" 
 echo "               [--prompt full|brief|none]"
 echo "               [--quiet]"  
 echo "               [--ignore_parameter_file]"
 echo "               [--check_parameters]"
 echo
 echo "      ehcsetup [--prompt full|brief|none]"
 echo "               [--quiet]"
 echo "                --remove"
 echo
 echo "      ehcsetup [--prompt full|brief]"
 echo "               [--add_password]"
 echo "               [--quiet]" 
 echo "               [--check_parameters]"
 echo "                --create_user"
 echo
 echo "      ehcsetup [--prompt full|brief]"
 echo "               [--default_manager]"
 echo "               [--quiet]"
 echo "               [--check_parameters]"
 echo "                --create_manager"
 echo
 echo "      ehcsetup [--prompt full|brief]"
 echo "               [--default_group]"
 echo "               [--quiet]" 
 echo "               [--check_parameters]"
 echo "                --create_group"
 echo
 echo "      ehcsetup  --help"
 echo
 echo
 echo "   REL      LANDP Release                  eg. L600"
 echo "   WSID     Workstation ID                 eg. AA"
 echo "   DIR      Location of LANDP Files        eg. /tmp/landp" 
 echo "   WDPATH   Path to Workstation Directory  eg. /opt/ibm/landp"
 echo
 echo "   * - To Be Specified For Non-Interactive Setup"      
 echo
}

#------------------------------
# exit_setup - Exit LANDP Setup
#------------------------------
exit_setup ()
{
 landp_display
 landp_logging "`$messages 10020 \"$m10020\"`"
 landp_display
 exit 1
}

#--------------------------------------------------------
# remove_landp - Remove Existing LANDP installation
#--------------------------------------------------------
remove_landp ()
{
 landp_display
 landp_logging "`$messages 10030 \"$m10030\"`"

 if [ ! -s "$landp_history" ] ; then
    landp_display 
    landp_logging "`$messages 10050 \"$m10050\" \"$landp_history\"`"
    exit_setup
 fi


 if [ $prompt_type = "full" ] ; then
    landp_display
    landp_display "`$messages 10710 \"$m10710\"`" 
    landp_display "`$messages 10720 \"$m10720\"`"
    landp_display 
    landp_display "`$messages 10730 \"$m10730\"`"
    landp_display "`$messages 10740 \"$m10740\"`"
    landp_display 
    landp_display "`$messages 10750 \"$m10750\"`"
    landp_display "`$messages 10760 \"$m10760\"`"
 fi
 
 echo
 echo -n "   `$messages 10040  \"$m10040\"`"

 read reply
 : ${reply:="0"}

 [ $reply != "1" ] && exit_setup

#
# Get Release List - Grep everything from history file that starts RLD
 
 landp_display
 release_list=`grep ^RLD $landp_history|awk -F' ' '{print $2}'|sort|uniq`

 if [ -n "$release_list" ] ; then
    if [ $prompt_type = "full" ] ; then
       landp_display "`$messages 10770 \"$m10770\"`"
       landp_display "`$messages 10780 \"$m10780\"`"
       landp_display "`$messages 10790 \"$m10790\"`"
       landp_display
       landp_display "`$messages 10800 \"$m10800\"`"
       landp_display "`$messages 10810 \"$m10810\"`"
    fi

    landp_display
    landp_logging "`$messages 10640 \"$m10640\"`"
    landp_display

    landp_logging "$release_list"
    landp_display

    echo -n "   `$messages 10650 \"$m10650\"`"
    read reply
    : ${reply:="None"}
    landp_display

    if [ $reply != "None" ] ; then
       release_delete_list=`sort $landp_history|uniq|cut -d' ' -f2- -|grep -w ^$reply|cut -d' ' -f2 -`
       delete_landp_directories $release_delete_list
       reconcile_history_file 
    fi
 fi

#
# Get Workstation List - Grep everything from history file that DOES NOT start RLx

 workstation_dir_list=`grep -v -w ^RL[[:alpha:]] $landp_history|sort|uniq`

 if [ -n "$workstation_dir_list" ] ; then
    if [ $prompt_type = "full" ] ; then
       landp_display "`$messages 10820 \"$m10820\"`"
       landp_display "`$messages 10830 \"$m10830\"`"
       landp_display "`$messages 10840 \"$m10840\"`"
       landp_display
       landp_display "`$messages 10850 \"$m10850\"`"
       landp_display "`$messages 10860 \"$m10860\"`"
       landp_display "`$messages 10870 \"$m10870\"`"
       landp_display
       landp_display "`$messages 10880 \"$m10880\"`"
       landp_display "`$messages 10890 \"$m10890\"`"
    fi

    landp_display
    landp_logging "`$messages 10660 \"$m10660\"`"
    landp_display

    list_workstation_dirs $workstation_dir_list
    landp_display

    echo -n "   `$messages 10670 \"$m10670\"`"
    read reply
    landp_display
    : ${reply:="None"}

    if [ $reply != "None" ] ; then
       workstation_delete_list=`grep -v ^RL[[:alpha:]] $landp_history|grep -w ^$reply|sort|uniq|awk -F' ' '{print $3}'`
       delete_landp_directories $workstation_delete_list
       reconcile_history_file 
    fi
 fi

 dircount=`grep -v ^RLR $landp_history|wc -l`

 if [ $dircount -le 0 ] ; then
    rm -f $landp_temp_history
    rm -f $landp_history
    rm -f $landp_parms
 fi
     

 landp_display
 exit 0
}

#---------------------------------------------------------------------------
# reconcile_history_file - Update landp history file to reflect changes made
#                          during phases of deletion. Deleted directories 
#                          are removed from the file. If after deleting all
#                          entries, only the mapping layer directory entry
#                          is present, clear the history file out.
#---------------------------------------------------------------------------
reconcile_history_file ()
{
 old_history_file=`sort $landp_history|uniq`
 rm -f $landp_temp_history
 touch $landp_temp_history

 set $old_history_file

 while [ $# -ne 0 ]
    do 
       parm1=$1; shift
       parm2=$1; shift
       parm3=$1; shift

       [ -d $parm3 ] && echo "$parm1 $parm2 $parm3" >> $landp_temp_history
    done

 dircount=`grep -v ^RLR $landp_temp_history|wc -l`

 if [ $dircount -le 0 ] ; then
    rm -f $landp_temp_history
    touch $landp_temp_history
 fi
     
 mv -f $landp_temp_history $landp_history
}

#---------------------------------------------------------------------------
# list_workstation_dirs - Display a List of Workstation Directories, with
#                         related Release and Path Information. 
#---------------------------------------------------------------------------
list_workstation_dirs ()
{
 while [ -n "$1" ]
    do
       ws_name=$1 ; shift
       ws_release=$1 ; shift
       ws_dir=$1 ; shift
       landp_logging "$ws_name ...... $ws_release ...... $ws_dir"
    done
}

#---------------------------------------------------------------------------
# delete_landp_directories - Delete Selected LANDP Directories
#---------------------------------------------------------------------------
delete_landp_directories ()
{
    delete_list=$*

    [ -z "$delete_list" ] && landp_logging "`$messages 10700 \"$m10700\"`" && return
 
    if [ $prompt_type = "full" ] ; then
       landp_display "`$messages 10900 \"$m10900\" \"$1\"`"
       landp_display "`$messages 10910 \"$m10910\" \"$1\"`"
       landp_display
       landp_display "`$messages 10920 \"$m10920\" \"$1\"`"
       landp_display "`$messages 10930 \"$m10930\" \"$1\"`"
       landp_display
       landp_display "`$messages 10940 \"$m10940\" \"$1\"`"
       landp_display
    fi   

    while [ $# -ne 0 ]
       do
          landp_logging "`$messages 10680 \"$m10680\" \"$1\"`"
          shift
       done
    landp_display
    
    echo -n "   `$messages 10690 \"$m10690\"`"
    read reply
    : ${reply:="0"}

    if [ $reply = "1" ] ; then
       set $delete_list
       while [ $# -ne 0 ]
          do
             rm -Rf $1
             private_landp_logging $1
             shift
          done
    fi 
  
    landp_display
}

#----------------------------------------------------------------------
# setup_parameters - Initialise Default Messages, Validate User, 
#                    Initialise Shell parameters, Retrieve Command Line 
#                    Input, Evaluate Run Parameters. 
#----------------------------------------------------------------------
setup_parameters ()
{
 landp_log=~/.landp_log
 rm -Rf $landp_log
 quiet="N"


# Check here for shellmsg (ehcsetup shell messages) in upper or lower case. This is
# because there is no guarantee that when the  files eventually arrive in the 
# distribution directory, their names will not have changed case.

 shell_messages=""
 [ -f "shellmsg" ] && shell_messages="shellmsg"
 [ -z "$shell_messages" ] && [ -f "SHELLMSG" ] && shell_messages="SHELLMSG"
 [ -z "$shell_messages" ] && landp_logging "Ehcsetup shell messages missing"


# Check here for ehcsmesg (ehcsetup message processor) in upper or lower case and
# ehcsetup.msg (ehcsetup messages) in upper or lower case. This is for the same
# reason as above.

 msg_file=""
 [ -x "ehcsetup.msg" ] && msg_file="ehcsetup.msg"
 [ -z "$msg_file" ] && [ -x "EHCSETUP.MSG" ] && msg_file="EHCSETUP.MSG"
 [ -z "$msg_file" ] && landp_logging "Ehcsetup messages missing"

 msg_processor=""
 [ -x "ehcsmesg" ] && msg_processor="ehcsmesg"
 [ -z "$msg_processor" ] && [ -x "EHCSMESG" ] && msg_processor="EHCSMESG"
 [ -z "$msg_processor" ] && landp_logging "Ehcsetup message processor missing"


# Check that we have a minimum configuration of message files to allow us to continue
# processing.  Must have  1) the message processor with either the message catalog or
# the shell messages or  2) the shell messages

 messages="$PWD/$msg_processor $PWD/$msg_file" 
 [ -z "$msg_processor" ] && messages="echo" && [ -z "$shell_messages" ] && exit 1 
 [ -z "$shell_messages" ] && [ -z "$msg_file" ] && exit 1


# Process shell messages if present. Also strip out any '0d' or ctrl-Z characters that 
# may have been added while being swapped from platform to platform.

 if [ -f "$shell_messages" ]; then
    cat $shell_messages|tr -d '\015''\032' > tmp_${shell_messages} 
    . $PWD/tmp_${shell_messages}
    rm -f tmp_${shell_messages}
 fi

 check_user

 landp_display
 landp_logging "`$messages 10060 \"$m10060\"`"

 linux_distribution="Unknown"
 ldc="/etc/issue"
 release=""
 landp_wsid=""
 wpath=""
 waction="cancel"
 laction="cancel" 
 pass_file="N"
 landp_tdir=""
 no_user="N"
 default_manager="N"
 default_group="N"
 prompt_type="full"
 no_parm_file="N"
 check_parameters="N"
 landp_add_group="Y"
 landp_add_manager="Y"
 landp_manager=""
 landp_user=""

##### Start of modifications =$A0 ###########
 logpath=""
 log2path=""
 lockpath=""
#####  End of modifications =$A0  ###########

 next_uid=500
 landp_group=500

#-----------------------------------------------
# Put distribution-specific variables here

 addopt=""
 auto_password="Y"

 if [ -f $ldc ] ; then
 
    grep "Red Hat" $ldc > /dev/null
    if [ $? -eq 0 ] ; then
       linux_distribution="Red Hat"
       addopt=" -n "
    fi 

    grep "SuSE" $ldc > /dev/null
    if [ $? -eq 0 ] ; then
       linux_distribution="SuSE"
       auto_password="N"
    fi

    grep "Turbolinux" $ldc > /dev/null
    if [ $? -eq 0 ] ; then
       linux_distribution="Turbolinux"
    fi

    grep "Caldera" $ldc > /dev/null
    if [ $? -eq 0 ] ; then
       linux_distribution="Caldera"
       auto_password="N"
    fi  

 fi

 landp_logging "Linux Distribution ... $linux_distribution"
#-----------------------------------------------

 LSB_app_landp="/opt/ibm/landp"
 LSB_var_landp="/var/opt/ibm/landp"
 landp_history=~/.landp_history
 landp_temp_history=~/.landp_temp_history
 env_script=".ehc_profile"
 env_script_parms=".ehc_profile_parms"
 landp_parms=~/.landp_parameters
 landp_tmp_file="landp_tmp_file"

 get_parameters $*

 print_copyright
 
 evaluate_landp_parameters
}

#---------------------------------------------------------------------------
# evaluate_landp_parameters - Evaluates the Distribution Directory, LANDP
#                             Release, Workstation Path and Workstation
#                             Directory based on following rules :
#
# Rules for Evaluating Distribution Directory
#                      Workstation Path
#                      Landp Release
#                      Workstation Directory
# 
#   1.  Values taken from command line parameters --landp_release,
#       --workstation_directory,  --distribution_directory and
#       --workstation_path.  
#   2.  If distribution directory unresolved, value taken from
#       .landp_parameters file in root directory, unless parameter file
#       to be ignored.
#   3.  If distribution directory still unresolved, user prompted for
#       value.
#   4.  If landp release and/or workstation directory parameter values 
#       unresolved, values are taken from autofbss file in distribution
#       directory, if directory and file present. 
#   5.  If any value still unresolved, value taken from .landp_parameters 
#       file in root directory.
#   6.  If any value still unresolved, user prompted for value.
#
#
# 'eval' is used after reading distribution directory and workstation path
# input from user to resolve any shell expansion (eg. ~,..,etc.)
#
#---------------------------------------------------------------------------
evaluate_landp_parameters ()
{
 [ "$no_parm_file" = "N" ] && read_landp_parameters

 [ -z "$landp_tdir" ] && landp_tdir=$last_landp_tdir

 if [ -z $landp_tdir ] ; then
    if [ "$prompt_type" != "none" ] ; then
       if [ "$prompt_type" = "full" ] ; then
          landp_display  "`$messages 10950 \"$m10950\"`" 
          landp_display  "`$messages 10960 \"$m10960\"`" 
          landp_display  "`$messages 10970 \"$m10970\"`" 
          landp_display  "`$messages 10980 \"$m10980\"`"
          landp_display 
          landp_display  "`$messages 10990 \"$m10990\"`" 
          landp_display  "`$messages 11000 \"$m11000\"`" 
          landp_display  "`$messages 11010 \"$m11010\"`" 
          landp_display           
       fi

       echo -n "   `$messages 10070 \"$m10070\" \"$PWD\"`"
       read landp_tdir
       : ${landp_tdir:="$PWD"}
       eval landp_tdir=$landp_tdir
       private_landp_logging "Distribution Directory=$landp_tdir" 
    fi
 fi

 [ -n $landp_tdir ] && [ -d $landp_tdir ] && get_autofbss_parameters
 [ -z "$release" ] && release=$last_release
 [ -z "$landp_wsid" ] && landp_wsid=$last_landp_wsid
 [ -z "$wpath" ] && wpath=$last_wpath

#
# If no prompts requested, check that all parameters specified OK on live run
#

 [ $prompt_type = "none" ] && check_automatic_setup && check_parameters

#
# Prompt for any required parameters
# 
 if [ -z "$release" ] && [ "$prompt_type" = "full" ] ; then
    landp_display
    landp_display "`$messages 11020 \"$m11020\"`"
    landp_display "`$messages 11030 \"$m11030\"`"
    landp_display "`$messages 11040 \"$m11040\"`"
    landp_display "`$messages 11050 \"$m11050\"`"
    landp_display
    landp_display "`$messages 11060 \"$m11060\"`"
    landp_display "`$messages 11070 \"$m11070\"`"
    landp_display "`$messages 11080 \"$m11080\"`"
    landp_display 
 fi

 while [ -z "$release" ] 
    do 
       echo -n "   `$messages 10080 \"$m10080\"`"
       read release
    done
 private_landp_logging "LANDP Release=$release"   


 if [ -z "$landp_wsid" ] && [ "$prompt_type" = "full" ] ; then
    landp_display
    landp_display "`$messages 11090 \"$m11090\"`"
    landp_display "`$messages 11100 \"$m11100\"`"
    landp_display "`$messages 11110 \"$m11110\"`"
    landp_display
    landp_display "`$messages 11120 \"$m11120\"`"
    landp_display "`$messages 11130 \"$m11130\"`"
    landp_display "`$messages 11140 \"$m11140\"`"
    landp_display 
 fi

 while [ -z "$landp_wsid" ] 
    do
       echo -n "   `$messages 10090 \"$m10090\"`"
       read landp_wsid
    done
 private_landp_logging "Workstation Directory=$landp_wsid"

 if [ -z "$waction" ] ; then
    if [ "$prompt_type" = "full" ] ; then 
       landp_display
       landp_display "`$messages 11150 \"$m11150\"`"
       landp_display "`$messages 11160 \"$m11160\"`"
       landp_display
       landp_display "`$messages 11170 \"$m11170\"`"
       landp_display
    fi
  
    echo -n "   `$messages 10100 \"$m10100\"`"
    read waction
    : ${waction:="cancel"}
 fi

 if [ -z "$laction" ] ; then
    if [ "$prompt_type" = "full" ] ; then
       landp_display
       landp_display "`$messages 11180 \"$m11180\"`"
       landp_display "`$messages 11190 \"$m11190\"`"
       landp_display
       landp_display "`$messages 11200 \"$m11200\"`"
       landp_display
    fi
 
    echo -n "   `$messages 10110 \"$m10110\"`"
    read laction
    : ${laction:="cancel"}
 fi

 landp_wpath="${LSB_app_landp}/$release"
 landp_mpath="$LSB_var_landp"

 if [ -z "$wpath" ] ; then
    if [ "$prompt_type" = "full" ] ; then
       landp_display
       landp_display "`$messages 11210 \"$m11210\"`"
       landp_display "`$messages 11220 \"$m11220\"`"
       landp_display
       landp_display "`$messages 11230 \"$m11230\"`"
       landp_display "`$messages 11240 \"$m11240\"`"
       landp_display "`$messages 11250 \"$m11250\"`"
       landp_display "`$messages 11260 \"$m11260\"`"
       landp_display "`$messages 11270 \"$m11270\"`"
       landp_display
    fi
 
    echo -n "   `$messages 10120 \"$m10120\" \"$landp_wpath\"`"
    read wpath
    : ${wpath:="$landp_wpath"}
    eval wpath=$wpath
 fi
 private_landp_logging "Workstation Directory Path=$wpath"

 check_parameters
}

#-------------------------------------------------------------------
# save_landp_parameters - save LANDP parameters in .landp_parameters
#                         Save the most recent values of ehcsetup
#                         parameters for later runs.
#-------------------------------------------------------------------
save_landp_parameters ()
{
 landp_display
 landp_logging "`$messages 10130 \"$m10130\"`"

 rm -Rf $landp_parms

 echo "last_release=$release" >> $landp_parms
 echo "last_landp_wsid=$landp_wsid" >> $landp_parms
 echo "last_wpath=$wpath" >> $landp_parms
 echo "last_landp_tdir=$landp_tdir" >> $landp_parms
}

#------------------------------------------------------------------------------
# create_environment_file - create the LANDP dot file containing env parameters
#------------------------------------------------------------------------------
create_environment_parameters ()
{
 landp_display
 landp_logging "`$messages 10140 \"$m10140\"`"

 echo "if [ \`id -gn\` != "landp" ] ; then" > $landp_wdir/$env_script
 echo "   echo " >> $landp_wdir/$env_script
 echo "   echo \"+-----------------------------------------------+\"" >> $landp_wdir/$env_script
 echo "   echo \"| Run 'newgrp landp' before running this script |\"" >> $landp_wdir/$env_script
 echo "   echo \"+-----------------------------------------------+\"" >> $landp_wdir/$env_script
 echo "   echo " >> $landp_wdir/$env_script
 echo "   return " >> $landp_wdir/$env_script
 echo "fi" >> $landp_wdir/$env_script
 
 echo "if [ -z \"\$EHC_ENV_SET\" ] ; then" >> $landp_wdir/$env_script
 echo "typeset ehc_srcpath=\"\$1\"" >> $landp_wdir/$env_script
 echo "[ -z \"\$ehc_srcpath\" ] && ehc_srcpath=$landp_wpath" >> $landp_wdir/$env_script
 echo "   export PATH=\$PATH:\$ehc_srcpath/bin:." >> $landp_wdir/$env_script
 echo "   export NLSPATH=\$NLSPATH:\$ehc_srcpath/msg/%N" >> $landp_wdir/$env_script
 echo "   export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:\$ehc_srcpath/lib" >> $landp_wdir/$env_script
 echo "   export CLASSPATH=\$CLASSPATH:$landp_wdir/ldpjava.jar" >> $landp_wdir/$env_script
 echo "   export EHC_BIN=\$ehc_srcpath/bin" >> $landp_wdir/$env_script

##### Start of modifications =$A0 ###########
 [ -n $logpath ] && echo "   export LOGPATH=$logpath" >> $landp_wdir/$env_script
 [ -n $log2path ] && echo "   export LOG2PATH=$log2path" >> $landp_wdir/$env_script
 [ -n $lockpath ] && echo "   export LOCKPATH=$lockpath" >> $landp_wdir/$env_script
#####  End of modifications =$A0  ###########  

 echo "   export EHC_ENV_SET=\"Y\"" >> $landp_wdir/$env_script
 echo "fi" >> $landp_wdir/$env_script
}

#-----------------------------------------------------------------------------
# get_autofbss_parameters - retrieve required parameters held in autofbss file.
#                           Retrieves the LANDP release and workstation id.
#-----------------------------------------------------------------------------
get_autofbss_parameters ()
{
 if [ -d $landp_tdir ] ; then
    cd $landp_tdir
          
    if [ -f "autofbss" ] ; then

##### Start of modifications =$A2 ###########
#       tmp_landp_wsid=`cat autofbss | grep -w ^loader | grep -w spv`
       tmp_landp_wsid=`cat autofbss | tr -d '\015''\032' | grep -w ^loader | grep -w spv`
#####  End of modifications =$A2  ###########

       if [ $? -eq 0 ] ; then
          tmp_landp_wsid=`echo $tmp_landp_wsid|sed 's/ //g'`
          tmp_landp_wsid=${tmp_landp_wsid#loaderspv}
          [ -z $landp_wsid ] && landp_wsid=`echo $tmp_landp_wsid|sed 's/\///'|sed 's/-//'`
       fi
    
##### Start of modifications =$A2 ###########
#       tmp_release=`cat autofbss | grep "prodlvl="`
       tmp_release=`cat autofbss | tr -d '\015''\032' | grep "prodlvl="`
#####  End of modifications =$A2  ###########

       if [ $? -eq 0 ] ; then
          tmp_release=`echo $tmp_release|sed 's/prodlvl/release/g'|sed 's/ //g'|sed 's/#//g'` 
          [ -z $release ] && eval $tmp_release
       fi  
    fi  
 fi   
}

#--------------------------------------------------------------------
# read_landp_parameters - read the LANDP parameters file and evaluate
#                         the parameters. These are the parameters 
#                         values used in the last ehcsetup run.
#--------------------------------------------------------------------
read_landp_parameters ()
{
 landp_display
 landp_logging "`$messages 10150 \"$m10150\"`"

 if [ -f "$landp_parms" ] ; then
    for entry in `cat $landp_parms`
       do
          eval $entry
          private_landp_logging $entry
       done
 fi
}

#-------------------------------------------------------------------------
# check_automatic_setup - Check that all required parameters are present
#                         to allow setup to run unattended
#-------------------------------------------------------------------------
check_automatic_setup ()
{
 landp_display
 landp_logging "`$messages 10160 \"$m10160\"`"
 landp_display

 default_manager="Y"
 default_group="Y"
 no_user="Y"
 auto_ok="Y"

 [ -z "$release" ]  && auto_ok="N" && landp_logging "   `$messages 10170 \"$m10170\"`"
 [ -z "$landp_wsid" ] && auto_ok="N" && landp_logging "   `$messages 10180 \"$m10180\"`"
 [ -z "$waction" ] && auto_ok="N" && landp_logging "   `$messages 10190 \"$m10190\"`"
 [ -z "$laction" ] && auto_ok="N" && landp_logging "   `$messages 10200 \"$m10200\"`"
 [ -z "$wpath" ] && auto_ok="N" && landp_logging "   `$messages 10210 \"$m10210\"`"
 [ -z "$landp_tdir" ]  && auto_ok="N" && landp_logging "   `$messages 10220 \"$m10220\"`"

 [ $auto_ok = "N" ]    && exit_setup  
}

#---------------------------------------------
# check_user - Check that present user is ROOT
#---------------------------------------------
check_user ()
{
 landp_display
 landp_logging "`$messages 10230 \"$m10230\"`"

 if [ `id -nu` != "root" ] ; then
    landp_display
    landp_logging "   `$messages 10240 \"$m10240\"`"
    private_landp_logging "User=`id -nu`"
    exit_setup
 fi
}

#--------------------------------------------------------------------------
# check_parameters - Present checklist of parameters to user then terminate
#--------------------------------------------------------------------------
check_parameters ()
{
 if [ "$check_parameters" = "Y" ] ; then
    landp_display
    landp_logging "`$messages 10250 \"$m10250\"`"
    landp_logging
    landp_logging "--release ........................... $release"
    landp_logging "--workstation_directory ............. $landp_wsid"
    landp_logging "--workstation_path .................. $wpath"
    landp_logging "--ws_dir_exist ...................... $waction"
    landp_logging "--release_exist ..................... $laction"
    landp_logging "--distribution_directory ............ $landp_tdir"
    landp_logging "--default_manager ................... $default_manager"
    landp_logging "--default_group ..................... $default_group" 
    landp_logging "--no_user ........................... $no_user"
    landp_logging "--prompt ............................ $prompt_type"
    landp_logging "--quiet ............................. $quiet"
    landp_logging "--ignore_parameter_file ............. $no_parm_file" 
    landp_logging
    exit_setup 
 fi
}

#--------------------------------------------------------------------
# directories_exist_action - Perform requested action if any LANDP or 
#                            workstation directory already exists.
#--------------------------------------------------------------------
directories_exist_action ()
{
 while [ -d $1 ] 
    do
       landp_display
       case $2 in
          clear)    landp_logging "   `$messages 10390 \"$m10390\" \"$1\"`"
                    break ;;
                  
          replace)  landp_logging "   `$messages 10410 \"$m10410\" \"$1\"`"
                    break ;;

          cancel|*) landp_logging "   `$messages 10380 \"$m10380\" \"$1\"`"
                    exit_setup ;;
                    
       esac
    done
}

#-----------------------------------
# make_link - Create individual link
#-----------------------------------
make_link ()
{
 ln -sf $1 $2
 if [ $? -ne 0 ] ;  then
    landp_logging "   `$messages 10260 \"$m10260\" \"$2\" \"$1\"`" $?
    exit_setup
 fi
}

#--------------------------------------------
# create_landp_links - Create the LANDP links
#--------------------------------------------
create_landp_links ()
{
 make_link $landp_wpath/lib/$2 $landp_wpath/lib/$1
 make_link $landp_wpath/lib/$3 $landp_wpath/lib/$2
}

#------------------------------------------------------------
# create_landp_directories - Create LANDP directory structure
#------------------------------------------------------------
create_landp_directories ()
{
 landp_display
 landp_logging "`$messages 10270 \"$m10270\"`"

 directories_exist_action $landp_wpath/bin $laction
 make_directory $landp_wpath/bin "RLD" "$release"
 directories_exist_action $landp_wpath/msg $laction
 make_directory $landp_wpath/msg "RLD" "$release"
 directories_exist_action $landp_wpath/lib $laction
 make_directory $landp_wpath/lib "RLD" "$release"
 make_directory $landp_mpath/.ml "RLR" "ALLLDP"
}

#------------------------------------------------------------
# create_creadb_directories - Create LANDP creadb directories
#------------------------------------------------------------
create_creadb_directories ()
{
 landp_display
 landp_logging "`$messages 10270 \"$m10270\"`"

 for token in `cat $landp_wdir/creadb`
    do 
       case $token in 
          mkdir)  nextp=1 ;; 

          chmod)  nextp=2 ;;

              *)  case $nextp in 
                     1) dir_exist="Y"
                        if [ ! -d "$token" ] ; then
                           make_directory $token "RLR" "ALLLDP"
                           change_owner $token
                           dir_exist="N"
                        fi 
                        nextp=0 ;;
 
                     2) dir_access=$token
                        nextp=3 ;;

                     3) [ $dir_exist = "N" ] && change_access $dir_access $token
                        nextp=0 ;;

                     *) nextp=0 ;;
                  esac; 
       esac; 
    done
}

#--------------------------------------------------------------------
# create_fbsspath_directories - Create LANDP fbsspath.dat directories
#--------------------------------------------------------------------
create_fbsspath_directories ()
{
 landp_display
 landp_logging "`$messages 10270 \"$m10270\"`"

 fold -b -w40 $landp_wdir/fbsspath.dat | awk '!/^PATH/{ print $0 }' > $landp_tmp_file

 if [ -s $landp_tmp_file ] ; then
    for landir in `cat $landp_tmp_file`
       do 
          tmpdir=`echo $landir|grep "/"` 
          if [ ! -z $tmpdir ] ; then 
             ldpdir=`echo $tmpdir|awk '{print substr ($0,3)}'`
             make_directory $ldpdir "RLR" "ALLLDP"
             change_owner $ldpdir
             change_access 775 $ldpdir
          fi
       done
    rm -f $landp_tmp_file
 fi
}

##### Start of modifications =$A0 ###########
#------------------------------------------------------------------------
# create_shfile_directories - Create LANDP shared file log and lock paths
#------------------------------------------------------------------------
create_shfile_directories ()
{
 landp_display
 landp_logging "`$messages 10270 \"$m10270\"`"
 landp_display

 echo -n "   `$messages 11570 \"$m11570\" \"$landp_mpath\"`"
 read logpath
 : ${logpath:="$landp_mpath"}
 eval logpath=$logpath

 private_landp_logging "Log Directory Path=$logpath"

 echo -n "   `$messages 11580 \"$m11580\" \"$logpath\"`"
 read log2path
 : ${log2path:="$logpath"}
 eval log2path=$log2path

 private_landp_logging "Log2 Directory Path=$log2path"

 echo -n "   `$messages 11590 \"$m11590\" \"$logpath\"`"
 read lockpath
 : ${lockpath:="$logpath"}
 eval lockpath=$lockpath

 private_landp_logging "Lock Directory Path=$lockpath"

 make_directory $logpath "RLR" "ALLLDP"
 make_directory $log2path "RLR" "ALLLDP"
 make_directory $lockpath "RLR" "ALLLDP"

 change_owner $logpath
 change_owner $log2path
 change_owner $lockpath

 change_access 775 $logpath
 change_access 775 $log2path
 change_access 775 $lockpath
}
#####  End of modifications =$A0  ###########

#----------------------------------------
# make_directory - Create LANDP directory
#----------------------------------------
make_directory ()
{
 mkdir -p $1
 private_landp_logging $1

 echo "$2" "$3" "$1" >> $landp_history
 if [ $? -ne 0 ] ; then
    landp_logging "   `$messages 10280 \"$m10280\" \"$1\"`" $?
    exit_setup
 fi
}

#---------------------------------------------------------------------------
# modify_owner_and_access - Update directory,file ownerships and permissions
#---------------------------------------------------------------------------
modify_owner_and_access ()
{
 landp_display
 landp_logging "`$messages 10290 \"$m10290\"`"

 change_owner $LSB_app_landp
 change_owner $landp_mpath
 change_owner $landp_wpath/bin
 change_owner $landp_wpath/msg
 change_owner $landp_wpath/lib
 change_owner $landp_mpath/.ml
 change_owner $landp_wdir

 change_access 775 $LSB_app_landp
 change_access 770 $landp_mpath
 change_access 755 $landp_wpath/bin
 change_access 755 $landp_wpath/msg
 change_access 755 $landp_wpath/lib
 change_access 770 $landp_mpath/.ml
 change_access 775 $landp_wdir
}

#-------------------------------------------------------
# change_owner - Change ownership of directory and files
#-------------------------------------------------------
change_owner ()
{
 private_landp_logging $1
 chown -fR $landp_manager.landp $1

 [ $? -ne 0 ] && landp_logging "   `$messages 10300 \"$m10300\" \"$1\"`" $?
}

#-------------------------------------------------------------
# change_access - Change directory and file access permissions
#-------------------------------------------------------------
change_access ()
{
 private_landp_logging $2
 chmod -fR $1 $2

 [ $? -ne 0 ] && landp_logging "   `$messages 10310 \"$m10310\" \"$2\"`" $?
}

#-------------------------------------------------------------------
# private_landp_logging - Log LANDP messages to file without display
#-------------------------------------------------------------------
private_landp_logging ()
{
 tmp_quiet=$quiet
 quiet="Y"
 landp_logging "$1"
 quiet=$tmp_quiet
}

#-------------------------------------------
# landp_logging - Log LANDP messages to file
#-------------------------------------------
landp_logging ()
{
 landp_display "$1"
 if [ $# -eq 2 ] ; then
    echo "$1" " RC="$2 >> $landp_log
 else
    echo "$1" >> $landp_log
 fi
}

#------------------------------------------------
# landp_display - Display LANDP message to screen
#------------------------------------------------
landp_display ()
{
 [ "$quiet" = "N" ] && echo -e $1
}

#-----------------------------------------------------------------
# copy_landp_file - Copy LANDP file from Distribution Directory to
#                   Destination Directory.
#-----------------------------------------------------------------
copy_landp_file ()
{
 tr_file=`echo $4 | tr [:upper:] [:lower:]`
 cp $2 $3/$tr_file 
 
 if [ $? -ne 0 ] ;  then
    landp_logging "   `$messages 10360 \"$m10360\" \"$2\" \"$3/$tr_file\"`" $?
    exit_setup
 fi
        
 landp_logging  "   Copying $1  --------> $3/$tr_file"
}

#-----------------------------------------------------------------------
# distribute_landp_files - Distribute LANDP files to directory structure
#-----------------------------------------------------------------------
distribute_landp_files ()
{
 landp_display
 landp_logging "`$messages 10320 \"$m10320\"`"

 if [ ! -d "$landp_tdir" ] ;  then
    landp_display
    landp_logging "   `$messages 10330 \"$m10330\" \"$landp_tdir\"`"
    landp_logging "   `$messages 10340 \"$m10340\"`"
    return
 fi

 cd $landp_tdir

 dirlist=`ls -1`
 dircount=`echo $dirlist|wc -c`
 
 if [ $dircount -le 1 ] ; then
    landp_logging "   `$messages 10350 \"$m10350\" \"$landp_tdir\"`"
    exit_setup
 fi

 landp_display

 for file in $dirlist
    do
#
#   move .exe files into landp bin directory
#
       new_file=`echo "$file" | sed 's/\.exe$//'`
       file $file | grep "LSB executable" >/dev/null

       if [ $file != $new_file -o $? -eq 0 ] ;  then
          copy_landp_file $file $file $landp_wpath/bin $new_file
          continue
       fi

#
#   move .msg files into landp msg directory - create link in bin directory
#
       new_file=`echo "$file" | tr [:upper:] [:lower:] | grep '\.msg$'`
       if [ "$new_file" ] ; then
          copy_landp_file $file $file $landp_wpath/msg $new_file
          make_link $landp_wpath/msg/$new_file $landp_wpath/bin/$new_file
          continue
       fi
#
#   move .so files into landp lib directory - expand into full shared object name,
#   create link in bin directory with original name
#
       new_file=`echo "$file" | tr [:upper:] [:lower:] | grep '\.so$'`
       file $file | grep "LSB shared object" >/dev/null

       if [ "$new_file" -o $? -eq 0 ] ; then
          unset landp_soname

          cp -f $file lib${new_file}
          if [ $? -ne 0 ] ;  then
             landp_logging "   `$messages 10360 \"$m10360\" \"$file\" \"lib${new_file}\"`" $?
             exit_setup
          fi

          landp_soname=`/sbin/ldconfig -XNlv lib${new_file} 2>/dev/null | \
                        awk -v f=lib${new_file} '{ if(index($0,f)) print $1 }'`

          copy_landp_file $file $file $landp_wpath/lib ${landp_soname}.0.0 
          rm -f lib${new_file}
          create_landp_links lib${new_file} $landp_soname ${landp_soname}.0.0
          make_link $landp_wpath/lib/${landp_soname}.0.0 $landp_wpath/bin/$new_file
          continue
       fi
#
#   move any other files into workstation directory - remove '0d' and ctrl-Z if text file
#
       cp $file tmp_${file}
       file $file | grep "ASCII text" > /dev/null
       [ $? -eq 0 ] && `cat $file|tr -d '\015''\032' > tmp_${file}`
       file $file | grep "script text" > /dev/null
       [ $? -eq 0 ] && `cat $file|tr -d '\015''\032' > tmp_${file}`

       copy_landp_file $file tmp_${file} $landp_wdir $file
       rm -f tmp_${file}
    done

#
#   make optional 'ehcremove' link
#   create additional LANDP directories from creadb and fbsspath.dat files (if present)
#   create additional LANDP directories if shfile##, *.dbn or *.pcn files are present
#

 [ -f "$landp_wdir/ehcsetup" ] && make_link $landp_wdir/ehcsetup $landp_wdir/ehcremove
 [ -f "$landp_wdir/creadb" ] && create_creadb_directories
 [ -f "$landp_wdir/fbsspath.dat" ] && create_fbsspath_directories

##### Start of modifications =$A0 ###########
 db_files=0
 [ $db_files -eq 0 ] && idir=`ls -1 $landp_wdir/*.pcn 2>/dev/null` && [ "$idir" ] && db_files=1
 [ $db_files -eq 0 ] && idir=`ls -1 $landp_wdir/*.dbn 2>/dev/null` && [ "$idir" ] && db_files=1
 [ $db_files -eq 0 ] && idir=`ls -1 $landp_wpath/bin/shfile* 2>/dev/null` && [ "$idir" ] && db_files=1
 [ $db_files -ne 0 ] && create_shfile_directories
#####  End of modifications =$A0  ###########
}

#------------------------------------------------------------------
# create_workstation_directory - Create LANDP Workstation directory 
#------------------------------------------------------------------
create_workstation_directory ()
{
 landp_display
 landp_logging "`$messages 10370 \"$m10370\"`"
 
 landp_wdir="${wpath:="$landp_wpath"}/$landp_wsid"
 directories_exist_action $landp_wdir $waction
 make_directory $landp_wdir "$landp_wsid" "$release"
}

#---------------------------------------------------------------
# create_landp_group - Create LANDP group (landp) if not present
#---------------------------------------------------------------
create_landp_group ()
{
 for line in `cat /etc/group`
    do
       group=`echo $line|cut -d: -f1 -`
       group_num=`echo $line|cut -d: -f3 -`

       if [ $group = "landp" ] ; then
          landp_group=$group_num
          landp_add_group="N"
          break
       fi

       [ $group_num -ge $landp_group ] && landp_group=$((group_num+1))
    done

 if [ $landp_add_group = "Y" ] ; then
    landp_display
    landp_logging "`$messages 10430 \"$m10430\"`"
  
    if [ $default_group = "N" ] ; then
       if [ "$prompt_type" = "full" ] ; then
          landp_display "`$messages 11280 \"$m11280\"`"
          landp_display "`$messages 11290 \"$m11290\"`"
          landp_display "`$messages 11300 \"$m11300\"`" 
          landp_display "`$messages 11310 \"$m11310\"`" 
          landp_display
          landp_display "`$messages 11320 \"$m11320\"`" 
          landp_display "`$messages 11330 \"$m11330\"`" 
          landp_display "`$messages 11340 \"$m11340\"`" 
       fi

       landp_display
       echo -n "   `$messages 10440 \"$m10440\" \"$landp_group\"`"
       read groupn

       landp_group=${groupn:=$landp_group}
    fi

    landp_display
    landp_logging "   `$messages 10450 \"$m10450\" \"$landp_group\"`"
    /usr/sbin/groupadd -g $landp_group landp

    if [ $? -ne 0 ] ; then
       landp_display
       landp_logging "   `$messages 10460 \$m10460\"`" $?
       exit_setup
    fi
 fi
}

#-------------------------------------------------------------------------
# create_landp_users - Create/update accounts as LANDP users (landp group)
#-------------------------------------------------------------------------
create_landp_users ()
{
 old_mask=`umask`
 umask 077

 [ $no_user = "Y" ] && landp_user="END"

 if [ -z "$landp_user" ] ; then
    landp_display
    landp_logging "`$messages 10470 \"$m10470\"`"

    if [ "$prompt_type" = "full" ] ; then
       landp_display
       landp_display "`$messages 11350 \"$m11350\"`"
       landp_display "`$messages 11360 \"$m11360\"`"
       landp_display "`$messages 11370 \"$m11370\"`"
       landp_display "`$messages 11380 \"$m11380\"`"
       landp_display
       landp_display "`$messages 11390 \"$m11390\"`"
       landp_display "`$messages 11400 \"$m11400\"`"
       landp_display "`$messages 11410 \"$m11410\"`"
    fi
 fi

 while [ "$landp_user" != "END" ]
    do
       echo
       echo -n "   `$messages 10480 \"$m10480\"`"
       read landp_user
       : ${landp_user:="END"}

       if [ "$landp_user" != "END" ] ; then
          existing_user="N"

          for line in `sed 's/ /_/g' /etc/passwd`
             do
                puser=`echo $line|cut -d: -f1 -`
                puid=`echo $line|cut -d: -f3 -`

                if [ $puser = $landp_user ] ; then
                   landp_display
                   landp_logging "   `$messages 10490 \"$m10490\" \"$landp_user\"`"
                   new_groups=`groups $landp_user|cut -d: -f2|sed 's/ //'|sed 's/ /,/g'`",landp"
                   landp_display
                   landp_logging "   `$messages 10500 \"$m10500\" \"$landp_user\"`"
                   /usr/sbin/usermod -G $new_groups $landp_user

                   if [ $? -ne 0 ] ; then
                      landp_logging "   `$messages 10510 \"$m10510\" \"$landp_user\"`" $?
                      mask $old_mask
                      exit_setup
                   fi

                   existing_user="Y"
                   break
                fi

                [ $puid -ge $next_uid ] && next_uid=$((puid+1))
             done

          if [ "$existing_user" = "N" ] ; then
             if [ "$prompt_type" = "full" ] ; then
                landp_display
                landp_display "`$messages 11420 \"$m11420\"`"
                landp_display "`$messages 11430 \"$m11430\"`"
                landp_display "`$messages 11440 \"$m11440\"`"
                landp_display 
                landp_display "`$messages 11450 \"$m11450\"`"
                landp_display "`$messages 11460 \"$m11460\"`"
                landp_display
                landp_display "`$messages 11470 \"$m11470\"`"
                landp_display "`$messages 11480 \"$m11480\"`"
                landp_display "`$messages 11490 \"$m11490\"`"
                landp_display 
             fi

             echo -n "   `$messages 10520 \"$m10520\" \"$landp_user\"`"
             read landp_user_home
             : ${landp_user_home:="/home/$landp_user"}

             if [ -d $landp_user_home ] ; then
                echo
                echo -n "   `$messages 10530 \"$m10530\" \"$landp_user_home\"`"
                read reply
                : ${reply:="1"}

                if [ $reply != "1" ] ; then
                   umask $old_mask
                   exit_setup
                fi
             fi

             if [ "$prompt_type" = "full" ] ; then
                landp_display
                landp_display "`$messages 11500 \"$m11500\"`"
                landp_display "`$messages 11510 \"$m11510\"`"
                landp_display "`$messages 11520 \"$m11520\"`"
                landp_display 
             fi
             
             echo -n "   `$messages 10540 \"$m10540\" \"$next_uid\"`"
             read user_id
             user_id=${user_id:=$next_uid}
             landp_user_id="-u $user_id"
             landp_display
             landp_logging "   `$messages 10550 \"$m10550\" \"$landp_user\" \"$user_id\"`"   
             landp_logging "   `$messages 10560 \"$m10560\" \"$landp_group\"`"
             /usr/sbin/useradd -d $landp_user_home -g $landp_group -m $addopt $landp_user_id $landp_user

             if [ $? -ne 0 ] ; then
                landp_logging "   `$messages 10570 \"$m10570\"`" $?
                umask $old_mask
                exit_setup
             fi

             if [ $auto_password = "Y" ] ; then
                landp_display
                landp_logging "   `$messages 10580 \"$m10580\"`"
                echo "${user_id}${landp_user}" | /usr/bin/passwd --stdin $landp_user >/dev/null

                if [ $? -ne 0 ] ; then
                   landp_logging "   `$messages 10590 \"$m10590\"`" $?
                   umask $old_mask
                   exit_setup
                fi

                [ $pass_file = "Y" ] && echo "$landp_user" "${user_id}${landp_user}" >> ~/.landp_passwords
             fi
          fi
       fi
    done

 umask $old_mask
}

#------------------------------------------------------
# create_manager_account - Create LANDP manager account
#------------------------------------------------------
create_manager_account ()
{
 for line in `sed 's/ /_/g' /etc/passwd`
    do
       landp_manager=`echo $line|cut -d: -f1 -`
       acc_comment=`echo $line|cut -d: -f5 -`

       if [ "$acc_comment" = "LANDP_Manager_Account" ]; then
          landp_add_manager="N"
          break
       fi
    done

 if [ $landp_add_manager = "Y" ] ; then 
    landp_display
    landp_logging "`$messages 10600 \"$m10600\"`"

    if [ $default_manager = "N" ] ; then
       if [ "$prompt_type" = "full" ] ; then
          landp_display 
          landp_display "`$messages 11530 \"$m11530\"`"
          landp_display "`$messages 11540 \"$m11540\"`"
          landp_display "`$messages 11550 \"$m11550\"`"
          landp_display "`$messages 11560 \"$m11560\"`"
       fi

       echo
       echo -n "   `$messages 10610 \"$m10610\"`"
       read landp_manager
    fi

    : ${landp_manager:="ldpmgr"}

    existing_user="N"

    for line in `sed 's/ /_/g' /etc/passwd`
       do
          puser=`echo $line|cut -d: -f1 -`

          if [ $puser = $landp_manager ] ; then
             new_groups=`groups $landp_manager|cut -d: -f2|sed 's/ //'|sed 's/ /,/g'`
             echo $new_groups | grep -w landp > /dev/null 

             if [ $? -eq 0 ] ; then
                existing_user="Y"
                break
             fi

             landp_display
             landp_logging "   `$messages 10490 \"$m10490\" \"$landp_manager\"`"
             new_groups=${new_groups}",landp"

             landp_display
             landp_logging "   `$messages 10500 \"$m10500\" \"$landp_manager\"`"
             /usr/sbin/usermod -G $new_groups $landp_manager

             if [ $? -ne 0 ] ; then
                landp_display
                landp_logging "   `$messages 10510 \"$m10510\" \"$landp_manager\"`" $?
                exit_setup
             fi

             existing_user="Y"
             break
          fi
       done

    if [ "$existing_user" = "N" ] ; then
       landp_display
       landp_logging "   `$messages 10620 \"$m10620\"`"
       /usr/sbin/useradd -g $landp_group -M $addopt $landp_manager -c "LANDP Manager Account"

       if [ $? -ne 0 ] ; then
          landp_display
          landp_logging "   `$messages 10630 \"$m10630\"`" $?
          exit_setup
       fi
    fi
 fi
}

#------------------------------------------
# Main - Setup LANDP (post-customization)
#------------------------------------------

setup_parameters $*

create_landp_directories

create_workstation_directory

create_landp_group

create_landp_users

create_manager_account

distribute_landp_files

create_environment_parameters

modify_owner_and_access

save_landp_parameters
